package com.bidbid.item.web;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.bidbid.item.dao.domain.Item;
import com.bidbid.item.service.IItemService;

import java.sql.Timestamp;

@Controller
public class ItemController {
	@Autowired
	IItemService itemService;
	
	@RequestMapping(value="/Item/Get.html")
	public String test(ModelMap modelMap){
		try {
			List<Item> allItems = itemService.getAllItems();
			System.out.println(allItems.size());
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "hello";
	}
	@RequestMapping(value="/Item/Add.htm")
	public String add(ModelMap modelMap){
		try{
			Timestamp ts = new Timestamp(System.currentTimeMillis());
			Item item = new Item();
			item.setItemId(0);
			item.setDescription("description");
			item.setItemName("ItemName");
			item.setPictureName("PictureName");
			item.setAddTime(ts);
			item.setItemState(Item.STATE_NOT_STARTED);
			item.setRecommended(true);
			itemService.AddItem(item);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "hello";
	}
}
